package com.xxxx.seckill.controller;

import com.xxxx.seckill.pojo.User;
import com.xxxx.seckill.service.UserService;
import com.xxxx.seckill.utils.MD5Utils;
import com.xxxx.seckill.utils.ValidatorUtils;
import com.xxxx.seckill.vo.LoginVo;
import com.xxxx.seckill.vo.RespBean;
import com.xxxx.seckill.vo.RespBeanEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * @Author:王亚栋
 * @Date:2023/2/12 17:19
 * @Version:1.0
 */
@Controller
@RequestMapping("login")
@Slf4j(topic = "LoginController")
public class LoginController {

    @Autowired
    private UserService userService;

    @GetMapping("/toLogin")
    public String toLogin(){

        log.info("进入到toLogin页面了");

        return "login";
    }

    @PostMapping("/doLogin")
    @ResponseBody
    public RespBean doLogin(@Valid LoginVo loginVo,
                            HttpServletRequest request,
                            HttpServletResponse response){

        return userService.doLogin(loginVo,request,response);
    }
}
